package com.csr.csrcheck.controller;

import com.csr.csrcheck.pojo.Business_risks;
import com.csr.csrcheck.pojo.Company;
import com.csr.csrcheck.pojo.Risk_classify;
import com.csr.csrcheck.pojo.Risk_type;
import com.csr.csrcheck.service.Business_risksService;
import com.csr.csrcheck.service.CompanyService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.service.ex.LawsuitException;
import com.csr.csrcheck.util.JsonResult;
import com.csr.csrcheck.util.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping({"business_risks"})
@RestController
public class Business_risksConntroller extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.Business_risksConntroller.class);

    @Resource
    private Business_risksService business_risksService;

    @Resource
    private CompanyService companyService;

    @GetMapping({"business_riskslist"})
    public JsonResult<List<Business_risks>> Companylist() {
        List<Business_risks> list = this.business_risksService.getBusiness_riskslist();
        if (list == null)
            throw new LawsuitException("");
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping({"bussiness"})
    public JsonResult<Object> bussiness(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize, @RequestParam(value = "name", required = false) String company_name) {
        PageResult pageResult = this.business_risksService.getListpage(pageNum, pageSize, company_name);
        if (pageResult == null)
            throw new CompanyException("");
        return new JsonResult(Integer.valueOf(0), "json", pageResult);
    }

    @RequestMapping(path = {"addbussiness"}, method = {RequestMethod.POST})
    public JsonResult<Void> addbussiness(Business_risks business_risks) {
        this.business_risksService.addBusiness(business_risks);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"updatebussiness"}, method = {RequestMethod.POST})
    public JsonResult<Void> updatebussiness(Business_risks business_risks) {
        this.business_risksService.updateBusiness(business_risks);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"deletebussiness/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Void> deletebussiness(@PathVariable("id") int id) {
        this.business_risksService.deleteBusiness(id);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"getcompany"}, method = {RequestMethod.POST})
    public JsonResult<List<Company>> getcompany() {
        List<Company> list = this.companyService.getCommpanyByid();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"getriskclassify"}, method = {RequestMethod.POST})
    public JsonResult<List<Risk_classify>> getriskclassify() {
        List<Risk_classify> list = this.business_risksService.findbylistclassify();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"getsriktype"}, method = {RequestMethod.POST})
    public JsonResult<List<Risk_type>> getsriktype() {
        List<Risk_type> list = this.business_risksService.findbylisttype();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"getbussinessbyid/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Business_risks> getbussinessbyid(@PathVariable("id") int id) {
        Business_risks business_risks = this.business_risksService.findlistbyid(id);
        return new JsonResult(Integer.valueOf(0), "json", business_risks);
    }
}
